<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"inkgn.gitee.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="git 诞生Git是一个开源的分布式版本控制系统，可以有效、高速的处理从很小到非常大的项目版本管理。 Git 是 Linus 大神 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。">
<meta property="og:type" content="article">
<meta property="og:title" content="git 学习笔记（一）">
<meta property="og:url" content="https://inkgn.gitee.io/2019/04/02/git/index.html">
<meta property="og:site_name" content="静水深流">
<meta property="og:description" content="git 诞生Git是一个开源的分布式版本控制系统，可以有效、高速的处理从很小到非常大的项目版本管理。 Git 是 Linus 大神 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/%E8%A1%A8%E6%83%85%E5%8C%85/-bed95d431ab46ff.jpg">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/gitnatu">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/2">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/3">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/1">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/1">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/4">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/6">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/Git_2_1.png">
<meta property="og:image" content="http://my-code.nos-eastchina1.126.net/jsrun/git/Git_2_2.png">
<meta property="article:published_time" content="2019-04-02T05:44:59.000Z">
<meta property="article:modified_time" content="2019-04-27T05:44:59.000Z">
<meta property="article:author" content="yinks">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://my-code.nos-eastchina1.126.net/jsrun/%E8%A1%A8%E6%83%85%E5%8C%85/-bed95d431ab46ff.jpg">

<link rel="canonical" href="https://inkgn.gitee.io/2019/04/02/git/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>git 学习笔记（一） | 静水深流</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">静水深流</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/categories" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-motto">

    <a href="/motto/motto" rel="section"><i class="fa fa-book fa-fw"></i>古训</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/me" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://inkgn.gitee.io/2019/04/02/git/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://blog-1253246719.cos.ap-chengdu.myqcloud.com/blog/user_info/face">
      <meta itemprop="name" content="yinks">
      <meta itemprop="description" content="长路漫漫，半程风雨，半程春">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="静水深流">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          git 学习笔记（一）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-04-02 13:44:59" itemprop="dateCreated datePublished" datetime="2019-04-02T13:44:59+08:00">2019-04-02</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-04-27 13:44:59" itemprop="dateModified" datetime="2019-04-27T13:44:59+08:00">2019-04-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Git%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index"><span itemprop="name">Git学习</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="git-诞生"><a href="#git-诞生" class="headerlink" title="git 诞生"></a>git 诞生</h3><p>Git是一个开源的分布式版本控制系统，可以有效、高速的处理从很小到非常大的项目版本管理。 Git 是 Linus 大神 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。</p>
<p>故事要从1991年说起，在那个操作系统需要购买的年代，Linus大神开发的开源Linux系统 ,吸引来全球许多开发者都参与其中为其贡献代码，<br>但是Linus作为代码的最终把关人员，每天需要把全球开发者发送来的代码，由本人进行查看合并。使用这种原始朴素的版本控制管理方式，可想而知  当时的  Linus大神是经历过绝望的！</p>
<p><img src="http://my-code.nos-eastchina1.126.net/jsrun/%E8%A1%A8%E6%83%85%E5%8C%85/-bed95d431ab46ff.jpg" alt="天妒嘤才"><br>于是Linus开始考察当时的版本控制软件，流行的SVN，VSS ,他看不上，因为这些都是属于集中式的控制系统他们不仅速度慢，而且必须联网才能使用。机缘巧合Linus找到了当时的一个分布式管理控制系统BitKeeper，此后BitKeeper一直是 Linux 内核开发人员在全球使用的主要源代码工具。开放源码社区中的有些人觉得BitKeeper 的许可证并不适合开放源码社区的工作，因此 Torvalds 决定着手研究许可证更为灵活的版本控制系统。尽管最初 Git 的开发是为了辅助 Linux 内核开发的过程，但是我们已经发现在很多其他自由软件项目中也使用了 Git。例如 很多 Freedesktop 的项目迁移到了 Git 上。</p>
<h3 id="git使用"><a href="#git使用" class="headerlink" title="git使用"></a>git使用</h3><p>git下载：<a target="_blank" rel="noopener" href="https://git-scm.com/downloads">下载地址</a><br>安装没啥好说的，一路Next。</p>
<p>（本教程为超级超级小白教程，大牛略过）</p>
<p>在此之前我先写一下git的一些基础命令：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ cd E:			<span class="comment">//进入E盘</span></span><br><span class="line">$ cd ../		<span class="comment">//进入上级目录</span></span><br><span class="line">$ cd ***		<span class="comment">//进入***文件夹（***为当前目录下）</span></span><br><span class="line">$ git --help	<span class="comment">//git 帮助</span></span><br></pre></td></tr></table></figure>

<p><strong>用户名</strong></p>
<p>首先我们需要创建用户名成为git的主人，相当于滴血认主啦</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git config --<span class="built_in">global</span> user.name <span class="string">&quot;username&quot;</span>	<span class="comment">//你的用户名</span></span><br><span class="line">git config --<span class="built_in">global</span> user.email <span class="string">&quot;你的邮箱&quot;</span>	<span class="comment">//你的邮箱  </span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 修改用户名及查看用户都可以使用此命令，建议邮箱及用户名设置与GitHub相同</span></span><br></pre></td></tr></table></figure>
<p>ok 至此，我们的账户已经有啦，那么现在我们就找一个文件夹作为我们的仓库，建立我们的<strong>大项目</strong>吧！,首先先跟着我一起看下面的导图吧</p>
<p><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/gitnatu" alt="git init"><br>使用<code>git init</code>命令初始化仓库<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/2" alt="git"><br>现在我们可以把我们的项目放进来了,此时我们使用<code>git status</code>命令查看当前状态<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/3" alt="zhut"><br>我们发现此时的index.txt 文本是红色的，那是因为这个新建的文本项目处于“自由”状态，也就是说此时index不受git管制跟踪，如果此时删除index文件是无法恢复 的，所以  在我git管制下居然还敢逍遥法外？肯定要红名处理！既然知道了原因我们就让Git跟踪index,。此时我们使用<code>git add index.txt</code>命令：<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/1"><br>此时我们发现index文件变绿了，这说明我们Git已经对index进行了跟踪，我们对于index一举一动都会在git的监视中，接下来我们执行<code>git comment -m &quot;描述&quot;</code>命令：<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/1" alt="git"><br>我们使用<code>git log</code>命令查看状态：<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/4" alt="git"><br>我们可以看到本次提交的一些详细信息，包括时间，描述，账户名，还有一串字符是用来恢复历史版本的<br>另外提一下，退出<code>git log</code>只需要在英文状态下点击<code> q</code>即可，刚用的时候还让我苦恼一阵子。</p>
<p>算了，先写到这吧，过几天在写同步上传GitHub的文章先上个图哈<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/6" alt="git"></p>
<hr>
<p>hello ! 大家好，我又回来了，今天我们衔接上面内容继续为大家讲解，今天内容是：</p>
<h3 id="git同步-——-github"><a href="#git同步-——-github" class="headerlink" title="git同步  ——  github"></a>git同步  ——  github</h3><p><strong>注册账户</strong></p>
<p>首先呢，我们需要注册一个GitHub账户，这里我们就不做过多的赘述了，不明白可以百度一下。<br>注册完成后我们可以先创建一个仓库，用来存放我们的代码以及同步本地代码，所以这里的仓库名最好和本地的相同。</p>
<p><strong>绑定账户</strong><br>想要让本地文件上传到GitHub其实有两种方法，分别是HTTPS，ssh两种方法本质都是一样的都要先确认身份再进行传输文件，在这里我们使用ssh方法。</p>
<p>我们直接在本地git输入命令生成密匙：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C <span class="string">&quot;your_email@youremail.com&quot;</span>  </span><br></pre></td></tr></table></figure>
<p>之后会让你确认一下秘钥的路径和密码，直接三次回车就好。然后在保存秘钥的路径下找到生成的.ssh文件夹一般在c盘账户目录下，进去，打开id_rsa.pub，复制里面的key。<br>回到github上，进入 Account Settings（账户配置），左边选择SSH Keys，Add SSH Key,title随便填，粘贴在你电脑上生成的key。<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/Git_2_1.png" alt="git"></p>
<p>添加成功后，还需要在本地关联远程仓库，注意这里要使用ssh，不要用https的地址，复制到剪切板.<br><img src="http://my-code.nos-eastchina1.126.net/jsrun/git/Git_2_2.png" alt="git"></p>
<p>在本地git输入：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote add origin git@github.com:yourName/yourRepo.git  </span><br></pre></td></tr></table></figure>
<p>成功后就相当于在你的本地库和远程仓库之间建立了映射，以后每次提交代码就不需要输入账号名和密码了，我们以后只需执行命令：<code>git push origin master</code>就能同步本地文件至远程仓库。</p>
<p><strong>常见问题（持续更新）</strong></p>
<ul>
<li>在这里补充一个小问题就是，在git推送文件的时候不允许远程仓库有某个文件而本地没有否则就会报错！解决办法就是先执行<code>git pull --rebase origin master  </code>之后再同步仓库命令就不会有问题啦。</li>
</ul>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>yinks
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://inkgn.gitee.io/2019/04/02/git/" title="git 学习笔记（一）">https://inkgn.gitee.io/2019/04/02/git/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Git/" rel="tag"># Git</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/11/23/newclass2/" rel="prev" title="JS学习笔记（二）">
      <i class="fa fa-chevron-left"></i> JS学习笔记（二）
    </a></div>
      <div class="post-nav-item">
    <a href="/2019/05/11/list4/" rel="next" title="一款超简约的网页级音乐播放器">
      一款超简约的网页级音乐播放器 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#git-%E8%AF%9E%E7%94%9F"><span class="nav-number">1.</span> <span class="nav-text">git 诞生</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git%E4%BD%BF%E7%94%A8"><span class="nav-number">2.</span> <span class="nav-text">git使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git%E5%90%8C%E6%AD%A5-%E2%80%94%E2%80%94-github"><span class="nav-number">3.</span> <span class="nav-text">git同步  ——  github</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="yinks"
      src="https://blog-1253246719.cos.ap-chengdu.myqcloud.com/blog/user_info/face">
  <p class="site-author-name" itemprop="name">yinks</p>
  <div class="site-description" itemprop="description">长路漫漫，半程风雨，半程春</div>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://gitee.com/inkgn" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;inkgn" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="/2087104694@qq.com" title="E-Mail → 2087104694@qq.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yinks</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
